package javango.contrib.jquery.widgets;

import com.google.inject.Inject;

import javango.api.Settings;
import javango.contrib.jquery.JqueryWidget;
import javango.forms.fields.BoundField;
import javango.forms.widgets.DateWidget;

public class JQueryDateWidget extends DateWidget implements JqueryWidget {

	Settings settings;
	@Inject
	public JQueryDateWidget(Settings settings) {
		super();
		this.settings = settings;
	}

	public String getScript(BoundField field) {
		// TODO Is this the correct way to grab a field's id?
		if (field.getField().isEditable()) {
			return String.format("$(\"#id_%1$s\")" +
					".datePicker({ buttonImage: '%2$scalendar.png' });", 
				(String)field.getHtmlName(),		// 1
				settings.get("jquery_media_url")); 	// 2
		}
		return null;
	}

}
